package com.guagua.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guagua.system.entity.Dict;
import com.guagua.system.mapper.DictMapper;
import com.guagua.system.service.DictService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService {
    
    @Override
    public List<Dict> getDictsByType(String dictType) {
        LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Dict::getDictType, dictType)
               .eq(Dict::getStatus, 0)
               .orderByAsc(Dict::getSort);
        return list(wrapper);
    }
    
    @Override
    public Map<String, List<Dict>> getAllDictMap() {
        LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Dict::getStatus, 0)
               .orderByAsc(Dict::getSort);
        List<Dict> dictList = list(wrapper);
        
        return dictList.stream()
                      .collect(Collectors.groupingBy(Dict::getDictType));
    }
} 